using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.Reflection;
using System.Globalization;
using System.Threading;
using System.IO;
using Widgetsphere.Autos.EFDAL;
using Widgetsphere.Autos.EFDAL.Entity;
using Widgetsphere.Autos.EFDAL.Interfaces;
using Widgetsphere.Autos.API.FacetedNavigation;
using HP.Datastore.Common;
using Widgetsphere.Autos.API;

namespace TestData
{
    public class Populate
    {
        private const int USER_COUNT = 2000;

        private string _masterConnection = string.Empty;
        private string _connection = string.Empty;
        private string _dbName = string.Empty;
        private int _count = 0;
        private List<string> nameList = new List<string>();
        private List<string> cityList = new List<string>();
        private List<string> streetList = new List<string>();
        private Random random = new Random();

        public event EventHandler Complete;

        protected void OnComplete(System.EventArgs e)
        {
            if (this.Complete != null)
                this.Complete(this, e);
        }

        public Populate(string masterConnection, string connection, string dbName, int count)
        {
            _masterConnection = masterConnection;
            _connection = connection;
            _dbName = dbName;
            _count = count;

            #region Last Names

            nameList.Add("SMITH");
            nameList.Add("JOHNSON");
            nameList.Add("WILLIAMS");
            nameList.Add("JONES");
            nameList.Add("BROWN");
            nameList.Add("DAVIS");
            nameList.Add("MILLER");
            nameList.Add("WILSON");
            nameList.Add("MOORE");
            nameList.Add("TAYLOR");
            nameList.Add("ANDERSON");
            nameList.Add("THOMAS");
            nameList.Add("JACKSON");
            nameList.Add("WHITE");
            nameList.Add("HARRIS");
            nameList.Add("MARTIN");
            nameList.Add("THOMPSON");
            nameList.Add("GARCIA");
            nameList.Add("MARTINEZ");
            nameList.Add("ROBINSON");
            nameList.Add("CLARK");
            nameList.Add("RODRIGUEZ");
            nameList.Add("LEWIS");
            nameList.Add("LEE");
            nameList.Add("WALKER");
            nameList.Add("HALL");
            nameList.Add("ALLEN");
            nameList.Add("YOUNG");
            nameList.Add("HERNANDEZ");
            nameList.Add("KING");
            nameList.Add("WRIGHT");
            nameList.Add("LOPEZ");
            nameList.Add("HILL");
            nameList.Add("SCOTT");
            nameList.Add("GREEN");
            nameList.Add("ADAMS");
            nameList.Add("BAKER");
            nameList.Add("GONZALEZ");
            nameList.Add("NELSON");
            nameList.Add("CARTER");
            nameList.Add("MITCHELL");
            nameList.Add("PEREZ");
            nameList.Add("ROBERTS");
            nameList.Add("TURNER");
            nameList.Add("PHILLIPS");
            nameList.Add("CAMPBELL");
            nameList.Add("PARKER");
            nameList.Add("EVANS");
            nameList.Add("EDWARDS");
            nameList.Add("COLLINS");
            nameList.Add("STEWART");
            nameList.Add("SANCHEZ");
            nameList.Add("MORRIS");
            nameList.Add("ROGERS");
            nameList.Add("REED");
            nameList.Add("COOK");
            nameList.Add("MORGAN");
            nameList.Add("BELL");
            nameList.Add("MURPHY");
            nameList.Add("BAILEY");
            nameList.Add("RIVERA");
            nameList.Add("COOPER");
            nameList.Add("RICHARDSON");
            nameList.Add("COX");
            nameList.Add("HOWARD");
            nameList.Add("WARD");
            nameList.Add("TORRES");
            nameList.Add("PETERSON");
            nameList.Add("GRAY");
            nameList.Add("RAMIREZ");
            nameList.Add("JAMES");
            nameList.Add("WATSON");
            nameList.Add("BROOKS");
            nameList.Add("KELLY");
            nameList.Add("SANDERS");
            nameList.Add("PRICE");
            nameList.Add("BENNETT");
            nameList.Add("WOOD");
            nameList.Add("BARNES");
            nameList.Add("ROSS");
            nameList.Add("HENDERSON");
            nameList.Add("COLEMAN");
            nameList.Add("JENKINS");
            nameList.Add("PERRY");
            nameList.Add("POWELL");
            nameList.Add("LONG");
            nameList.Add("PATTERSON");
            nameList.Add("HUGHES");
            nameList.Add("FLORES");
            nameList.Add("WASHINGTON");
            nameList.Add("BUTLER");
            nameList.Add("SIMMONS");
            nameList.Add("FOSTER");
            nameList.Add("GONZALES");
            nameList.Add("BRYANT");
            nameList.Add("ALEXANDER");
            nameList.Add("RUSSELL");
            nameList.Add("GRIFFIN");
            nameList.Add("DIAZ");
            nameList.Add("HAYES");

            #endregion

            #region Cities

            cityList.Add("Abba");
            cityList.Add("Abbeville");
            cityList.Add("Acworth");
            cityList.Add("Adairsville");
            cityList.Add("Adel");
            cityList.Add("Adrian");
            cityList.Add("Ailey");
            cityList.Add("Alamo");
            cityList.Add("Alapaha");
            cityList.Add("Albany");
            cityList.Add("Allenhurst");
            cityList.Add("Alma");
            cityList.Add("Alma");
            cityList.Add("Alpharetta");
            cityList.Add("Alston");
            cityList.Add("Amboy");
            cityList.Add("Ambrose");
            cityList.Add("Americus");
            cityList.Add("Appling");
            cityList.Add("Arlington");
            cityList.Add("Ashburn");
            cityList.Add("Athens");
            cityList.Add("Athens-Clarke County");
            cityList.Add("Atkinson");
            cityList.Add("Atlanta");
            cityList.Add("Attapulgus");
            cityList.Add("Auburn");
            cityList.Add("Augusta");
            cityList.Add("Augusta-Richmond County");
            cityList.Add("Austell");
            cityList.Add("Avondale Estates");
            cityList.Add("Axson");
            cityList.Add("Baconton");
            cityList.Add("Baden");
            cityList.Add("Bainbridge");
            cityList.Add("Bainbridge");
            cityList.Add("Baldwin");
            cityList.Add("Bannockburn");
            cityList.Add("Barnesville");
            cityList.Add("Barney");
            cityList.Add("Barretts");
            cityList.Add("Barwick");
            cityList.Add("Baxley");
            cityList.Add("Bemiss");
            cityList.Add("Berkeley Lake");
            cityList.Add("Berlin");
            cityList.Add("Blackshear");
            cityList.Add("Blairsville");
            cityList.Add("Blakely");
            cityList.Add("Bloomingdale");
            cityList.Add("Blue Ridge");
            cityList.Add("Bogart");
            cityList.Add("Boston");
            cityList.Add("Bowdon");
            cityList.Add("Bowens Mill");
            cityList.Add("Bowman");
            cityList.Add("Braselton");
            cityList.Add("Bremen");
            cityList.Add("Brinson");
            cityList.Add("Bristol");
            cityList.Add("Bronwood");
            cityList.Add("Brookfield");
            cityList.Add("Brooklet");
            cityList.Add("Brooks");
            cityList.Add("Broxton");
            cityList.Add("Brunswick");
            cityList.Add("Buchanan");
            cityList.Add("Buena Vista");
            cityList.Add("Buford");
            cityList.Add("Bushnell");
            cityList.Add("Byromville");
            cityList.Add("Byron");
            cityList.Add("Cairo");
            cityList.Add("Camilla");
            cityList.Add("Canton");
            cityList.Add("Carnesville");
            cityList.Add("Carrollton");
            cityList.Add("Cartersville");
            cityList.Add("Cave Spring");
            cityList.Add("Cecil");
            cityList.Add("Cedartown");
            cityList.Add("Centerville");
            cityList.Add("Chamblee");
            cityList.Add("Chatsworth");
            cityList.Add("Chauncey");
            cityList.Add("Chester");
            cityList.Add("Chickamauga");
            cityList.Add("Chula");
            cityList.Add("City of Calhoun");
            cityList.Add("City of Summerville");
            cityList.Add("Clarkesville");
            cityList.Add("Clarkston");
            cityList.Add("Claxton");
            cityList.Add("Clayton");
            cityList.Add("Cleveland");
            cityList.Add("Clyatteville");
            cityList.Add("Clyo");
            cityList.Add("Cobbtown");
            cityList.Add("Cochran");
            cityList.Add("Cogdell");
            cityList.Add("Cohutta");
            cityList.Add("Colesburg");
            cityList.Add("College Park");
            cityList.Add("Collins");
            cityList.Add("Colquitt");
            cityList.Add("Columbus");
            cityList.Add("Commerce");
            cityList.Add("Conyers");
            cityList.Add("Coolidge");
            cityList.Add("Cordele");
            cityList.Add("Cornelia");
            cityList.Add("Council");
            cityList.Add("Country Club Estate");
            cityList.Add("Coverdale");
            cityList.Add("Covington");
            cityList.Add("Cox");
            cityList.Add("Crawfordville");
            cityList.Add("Crescent");
            cityList.Add("Culloden");
            cityList.Add("Cumming");
            cityList.Add("Cusseta");
            cityList.Add("Cuthbert");
            cityList.Add("Dacula");
            cityList.Add("Dahlonega");
            cityList.Add("Daisy");
            cityList.Add("Dakota");
            cityList.Add("Dallas");
            cityList.Add("Dalton");
            cityList.Add("Damascus");
            cityList.Add("Danielsville");
            cityList.Add("Darien");
            cityList.Add("Dasher");
            cityList.Add("Dawson");
            cityList.Add("Dawsonville");
            cityList.Add("Decatur");
            cityList.Add("Denmark");
            cityList.Add("Dillard");
            cityList.Add("Dixie");
            cityList.Add("Dock Junction");
            cityList.Add("Doerun");
            cityList.Add("Donalsonville");
            cityList.Add("Doraville");
            cityList.Add("Douglas");
            cityList.Add("Douglasville");
            cityList.Add("Dover Bluff");
            cityList.Add("DuPont");
            cityList.Add("Dublin");
            cityList.Add("Dudley");
            cityList.Add("Duluth");
            cityList.Add("East Dublin");
            cityList.Add("East Point");
            cityList.Add("Eastman");
            cityList.Add("Eatonton");
            cityList.Add("Ebenezer");
            cityList.Add("Edison");
            cityList.Add("Edith");
            cityList.Add("Egypt");
            cityList.Add("Elberton");
            cityList.Add("Eldorado");
            cityList.Add("Ellabelle");
            cityList.Add("Ellaville");
            cityList.Add("Ellenton");
            cityList.Add("Ellijay");
            cityList.Add("Enigma");
            cityList.Add("Euharlee");
            cityList.Add("Eulonia");
            cityList.Add("Everitt");
            cityList.Add("Fairburn");
            cityList.Add("Fairmont");
            cityList.Add("Fargo");
            cityList.Add("Fayetteville");
            cityList.Add("Fitzgerald");
            cityList.Add("Flemington");
            cityList.Add("Flowery Branch");
            cityList.Add("Folkston");
            cityList.Add("Forest Park");
            cityList.Add("Forsyth");
            cityList.Add("Fort Gaines");
            cityList.Add("Fort Oglethorpe");
            cityList.Add("Fort Stewart");
            cityList.Add("Fort Valley");
            cityList.Add("Franklin");
            cityList.Add("Fruitland");
            cityList.Add("Funston");
            cityList.Add("Gainesville");
            cityList.Add("Garden City");
            cityList.Add("Garfield");
            cityList.Add("Geneva");
            cityList.Add("Georgetown");
            cityList.Add("Gibson");
            cityList.Add("Glennville");
            cityList.Add("Glenwood");
            cityList.Add("Glory");
            cityList.Add("Graham");
            cityList.Add("Gray");
            cityList.Add("Greensboro");
            cityList.Add("Greenville");
            cityList.Add("Griffin");
            cityList.Add("Grooverville");
            cityList.Add("Groveland");
            cityList.Add("Grovetown");
            cityList.Add("Gumbranch");
            cityList.Add("Guyton");
            cityList.Add("Hagan");
            cityList.Add("Hahira");
            cityList.Add("Hamilton");
            cityList.Add("Hampton");
            cityList.Add("Hapeville");
            cityList.Add("Harding");
            cityList.Add("Harding");
            cityList.Add("Hardwicke");
            cityList.Add("Harrietts Bluff");
            cityList.Add("Hartwell");
            cityList.Add("Hawkinsville");
            cityList.Add("Haylon");
            cityList.Add("Hazlehurst");
            cityList.Add("Helena");
            cityList.Add("Hepzibah");
            cityList.Add("Hiawassee");
            cityList.Add("Hickox");
            cityList.Add("Higgston");
            cityList.Add("Hinesville");
            cityList.Add("Hiram");
            cityList.Add("Hoboken");
            cityList.Add("Hogansville");
            cityList.Add("Holly Springs");
            cityList.Add("Holt");
            cityList.Add("Homeland");
            cityList.Add("Homer");
            cityList.Add("Homerville");
            cityList.Add("Hopeulikit");
            cityList.Add("Hortense");
            cityList.Add("Howell");
            cityList.Add("Inaha");
            cityList.Add("Iron City");
            cityList.Add("Irwinton");
            cityList.Add("Irwinville");
            cityList.Add("Isle of Hope-Dutch Island");
            cityList.Add("Jackson");
            cityList.Add("Janis");
            cityList.Add("Jasper");
            cityList.Add("Jefferson");
            cityList.Add("Jeffersonville");
            cityList.Add("Jesup");
            cityList.Add("Johns Creek");
            cityList.Add("Jonesboro");
            cityList.Add("Keller");
            cityList.Add("Kennesaw");
            cityList.Add("Kinderlou");
            cityList.Add("Kings Bay Base");
            cityList.Add("Kingsland");
            cityList.Add("Kirkland");
            cityList.Add("Kite");
            cityList.Add("LaFayette");
            cityList.Add("LaGrange");
            cityList.Add("Lake City");
            cityList.Add("Lake Park");
            cityList.Add("Lakeland");
            cityList.Add("Lanier");
            cityList.Add("Lawrenceville");
            cityList.Add("Lax");
            cityList.Add("Leary");
            cityList.Add("Leefield");
            cityList.Add("Leesburg");
            cityList.Add("Lenox");
            cityList.Add("Lexington");
            cityList.Add("Lilburn");
            cityList.Add("Lincolnton");
            cityList.Add("Lithonia");
            cityList.Add("Locust Grove");
            cityList.Add("Loganville");
            cityList.Add("Lookout Mountain");
            cityList.Add("Louisville");
            cityList.Add("Lovejoy");
            cityList.Add("Ludowici");
            cityList.Add("Lulaton");
            cityList.Add("Lumber City");
            cityList.Add("Lumpkin");
            cityList.Add("Lyons");
            cityList.Add("Macon");
            cityList.Add("Madison");
            cityList.Add("Manassas");
            cityList.Add("Manchester");
            cityList.Add("Marietta");
            cityList.Add("Mayday");
            cityList.Add("McDonough");
            cityList.Add("McIntosh");
            cityList.Add("McIntyre");
            cityList.Add("McRae");
            cityList.Add("Meigs");
            cityList.Add("Meldrim");
            cityList.Add("Mershon");
            cityList.Add("Metter");
            cityList.Add("Midway");
            cityList.Add("Milan");
            cityList.Add("Milledgeville");
            cityList.Add("Millen");
            cityList.Add("Milton");
            cityList.Add("Moniac");
            cityList.Add("Monroe");
            cityList.Add("Montezuma");
            cityList.Add("Montgomery");
            cityList.Add("Monticello");
            cityList.Add("Montrose");
            cityList.Add("Mora");
            cityList.Add("Morgan");
            cityList.Add("Morrow");
            cityList.Add("Morven");
            cityList.Add("Moultrie");
            cityList.Add("Mount Vernon");
            cityList.Add("Mount Zion");
            cityList.Add("Mountain Park");
            cityList.Add("Mystic");
            cityList.Add("Nahunta");
            cityList.Add("Nankin");
            cityList.Add("Nashville");
            cityList.Add("Needmore");
            cityList.Add("Nelson");
            cityList.Add("Nevils");
            cityList.Add("New Rock Hill");
            cityList.Add("Newnan");
            cityList.Add("Newton");
            cityList.Add("Nicholls");
            cityList.Add("Norcross");
            cityList.Add("Norman Park");
            cityList.Add("Oakwood");
            cityList.Add("Ochlocknee");
            cityList.Add("Ocilla");
            cityList.Add("Odum");
            cityList.Add("Offerman");
            cityList.Add("Offerman");
            cityList.Add("Oglethorpe");
            cityList.Add("Omega");
            cityList.Add("Osterfield");
            cityList.Add("Ousley");
            cityList.Add("Oxford");
            cityList.Add("Palmetto");
            cityList.Add("Parrott");
            cityList.Add("Patterson");
            cityList.Add("Peachtree City Website");
            cityList.Add("Pearson");
            cityList.Add("Pelham");
            cityList.Add("Pembroke");
            cityList.Add("Perry");
            cityList.Add("Phillipsburg");
            cityList.Add("Pine Lake");
            cityList.Add("Pineora");
            cityList.Add("Pineview");
            cityList.Add("Pooler");
            cityList.Add("Port Wentworth");
            cityList.Add("Portal");
            cityList.Add("Potter");
            cityList.Add("Poulan");
            cityList.Add("Powder Springs");
            cityList.Add("Preston");
            cityList.Add("Pridgen");
            cityList.Add("Pulaski");
            cityList.Add("Queensland");
            cityList.Add("Quitman");
            cityList.Add("Race Pond");
            cityList.Add("Ray City");
            cityList.Add("Rebecca");
            cityList.Add("Register");
            cityList.Add("Reidsville");
            cityList.Add("Remerton");
            cityList.Add("Rentz");
            cityList.Add("Retreat");
            cityList.Add("Riceboro");
            cityList.Add("Richmond Hill");
            cityList.Add("Ridgeville");
            cityList.Add("Rincon");
            cityList.Add("Ringgold");
            cityList.Add("Riverdale");
            cityList.Add("Riverside");
            cityList.Add("Rochelle");
            cityList.Add("Rockingham");
            cityList.Add("Rockmart");
            cityList.Add("Rome");
            cityList.Add("Roswell");
            cityList.Add("Royston");
            cityList.Add("Rutledge");
            cityList.Add("Saint George");
            cityList.Add("Sale City");
            cityList.Add("Sandersville");
            cityList.Add("Sandy Springs");
            cityList.Add("Sasser");
            cityList.Add("Savannah");
            cityList.Add("Screven");
            cityList.Add("Senoia");
            cityList.Add("Sessoms");
            cityList.Add("Shawnee");
            cityList.Add("Shellman Bluff");
            cityList.Add("Sirmans");
            cityList.Add("Skidaway Island");
            cityList.Add("Smithville");
            cityList.Add("Smyrna");
            cityList.Add("Snellville");
            cityList.Add("Social Circle");
            cityList.Add("Soperton");
            cityList.Add("South Newport");
            cityList.Add("Sparks");
            cityList.Add("Sparta");
            cityList.Add("Springfield");
            cityList.Add("St. Marys");
            cityList.Add("St. Simons Island");
            cityList.Add("Statenville");
            cityList.Add("Statesboro");
            cityList.Add("Sterling");
            cityList.Add("Stillmore");
            cityList.Add("Stillwell");
            cityList.Add("Stilson");
            cityList.Add("Stockbridge");
            cityList.Add("Stockton");
            cityList.Add("Stone Mountain");
            cityList.Add("Sugar Hill");
            cityList.Add("Sumner");
            cityList.Add("Sunbury");
            cityList.Add("Sunsweet");
            cityList.Add("Surrency");
            cityList.Add("Suwanee");
            cityList.Add("Swainsboro");
            cityList.Add("Sycamore");
            cityList.Add("Sylvania");
            cityList.Add("Sylvester");
            cityList.Add("Talbotton");
            cityList.Add("Tallapoosa");
            cityList.Add("Tarboro");
            cityList.Add("Tarver");
            cityList.Add("Temple");
            cityList.Add("Thalman");
            cityList.Add("Thelma");
            cityList.Add("Thomaston");
            cityList.Add("Thomasville");
            cityList.Add("Thomson");
            cityList.Add("Thunderbolt");
            cityList.Add("Tifton");
            cityList.Add("Toccoa");
            cityList.Add("Toomsboro");
            cityList.Add("Townsend");
            cityList.Add("Trenton");
            cityList.Add("Trudie");
            cityList.Add("Twin City");
            cityList.Add("Twin Lakes");
            cityList.Add("Ty Ty");
            cityList.Add("Tybee Island");
            cityList.Add("Tyrone");
            cityList.Add("Unadilla");
            cityList.Add("Union City");
            cityList.Add("Unionville");
            cityList.Add("Upton");
            cityList.Add("Uvalda");
            cityList.Add("Valdosta");
            cityList.Add("Valona");
            cityList.Add("Vernonburg");
            cityList.Add("Vidalia");
            cityList.Add("Vienna");
            cityList.Add("Villa Rica");
            cityList.Add("Walthourville");
            cityList.Add("Warner Robins");
            cityList.Add("Warrenton");
            cityList.Add("Warwick");
            cityList.Add("Washington");
            cityList.Add("Waterloo");
            cityList.Add("Watkinsville");
            cityList.Add("Waverly");
            cityList.Add("Waycross");
            cityList.Add("Waynesboro");
            cityList.Add("Waynesville");
            cityList.Add("Weber");
            cityList.Add("West Green");
            cityList.Add("West Point");
            cityList.Add("Westwood");
            cityList.Add("Whigham");
            cityList.Add("White Oak");
            cityList.Add("Whitmarsh Island");
            cityList.Add("Willacoochee");
            cityList.Add("Wilmington Island");
            cityList.Add("Winder");
            cityList.Add("Winokur");
            cityList.Add("Withers");
            cityList.Add("Woodbine");
            cityList.Add("Woodstock");
            cityList.Add("Worth");
            cityList.Add("Wray");
            cityList.Add("Wrightsville");
            cityList.Add("Zebulon");

            #endregion

            #region streetList

            streetList.Add("ABBOTTS BRIDGE");
            streetList.Add("ABBOTTS CLOSE");
            streetList.Add("ADDISON");
            streetList.Add("ADMIRAL");
            streetList.Add("ALDERMAN");
            streetList.Add("AMBERLILLY");
            streetList.Add("AMERICAS CUP");
            streetList.Add("ANTLER");
            streetList.Add("ARDSLEY");
            streetList.Add("ARNCLIFFE");
            streetList.Add("ASCALON");
            streetList.Add("ASHEBOURNE");
            streetList.Add("ASHEWOODE DOWNS");
            streetList.Add("ASHLEAF");
            streetList.Add("ASHSHIRE");
            streetList.Add("ASHTREE");
            streetList.Add("ASHVALE OVERLOOK");
            streetList.Add("ASHWICK");
            streetList.Add("ASHWIND");
            streetList.Add("ASPEN FOREST");
            streetList.Add("AUTUMN SAGE");
            streetList.Add("AVALON");
            streetList.Add("BALLENTREE");
            streetList.Add("BANNERHORN");
            streetList.Add("BARRINGTON");
            streetList.Add("BARRINGTON");
            streetList.Add("BARTON");
            streetList.Add("BAY POINTE");
            streetList.Add("BEACON HILL");
            streetList.Add("BECKENGON");
            streetList.Add("BELLFLOWER");
            streetList.Add("BELMONT CHASE");
            streetList.Add("BENT CREEK");
            streetList.Add("BENTHAM");
            streetList.Add("BENTLEY HALL");
            streetList.Add("BENTWOOD");
            streetList.Add("BIG CREEK");
            streetList.Add("BIG CREEK OVERLOOK");
            streetList.Add("BIRCH FOREST");
            streetList.Add("BITTERCRESS");
            streetList.Add("BLACK TAIL");
            streetList.Add("BLACKHEATH");
            streetList.Add("BLUE SPRUCE");
            streetList.Add("BLUEGRASS VALLEY");
            streetList.Add("BLUESEDGE");
            streetList.Add("BOXWOOD");
            streetList.Add("BRAFFERTON");
            streetList.Add("BRANDYWINE");
            streetList.Add("BRECKENRIDGE");
            streetList.Add("BRIDGE POINTE");
            streetList.Add("BRIGHTMORE");
            streetList.Add("BRIGHTMORE DOWNS");
            streetList.Add("BRISTLE STONE");
            streetList.Add("BRISTOLSTONE");
            streetList.Add("BROADLEAF");
            streetList.Add("BROOK LANDING");
            streetList.Add("BROOK MEADOW");
            streetList.Add("BROOK POND");
            streetList.Add("BROOKWATER");
            streetList.Add("BUCK HOLLOW");
            streetList.Add("BUCKS CLUB");
            streetList.Add("CABOT");
            streetList.Add("CADELEIGH");
            streetList.Add("CALBORNE");
            streetList.Add("CALLA");
            streetList.Add("CAMBRIDGE");
            streetList.Add("CAMBRIDGE CREST");
            streetList.Add("CAMDEN");
            streetList.Add("CANEY CREEK");
            streetList.Add("CANFIELD");
            streetList.Add("CANNONERO");
            streetList.Add("CARDIFF");
            streetList.Add("CARIBOU");
            streetList.Add("CARNOUSTIE");
            streetList.Add("CARRINGTON");
            streetList.Add("CHASEWOOD");
            streetList.Add("CHERRINGHAM");
            streetList.Add("CHESTNUT");
            streetList.Add("CHICHESTER");
            streetList.Add("CHICORY");
            streetList.Add("CHIPPENHAM");
            streetList.Add("CHRISTOPHER ROBIN");
            streetList.Add("CHURCHILL");
            streetList.Add("CLEARVIEW");
            streetList.Add("CLIPPER");
            streetList.Add("CLIPPER BAY");
            streetList.Add("CLUB");
            streetList.Add("CLUB HOUSE");
            streetList.Add("COLTON CREST");
            streetList.Add("COLUMBIA BAY");
            streetList.Add("COMMONS");
            streetList.Add("COMPASS POINTE");
            streetList.Add("COMPASS POINTE CHASE");
            streetList.Add("COMPTON HALL");
            streetList.Add("CONCORD");
            streetList.Add("CONCORD HALL");
            streetList.Add("CORNISH");
            streetList.Add("COTTON CREEK ENTRY");
            streetList.Add("COUNTRY PLACE");
            streetList.Add("COURAGEOUS WAKE");
            streetList.Add("CREEK LANDING");
            streetList.Add("CREEK RIDGE");
            streetList.Add("CREEK RIDGE POINTE");
            streetList.Add("CREEK RUN");
            streetList.Add("CREEKSIDE");
            streetList.Add("CREEKVIEW");
            streetList.Add("CREPE MYRTLE");
            streetList.Add("CRESTHAVEN");
            streetList.Add("CROFTON");
            streetList.Add("CROFTON FARMS");
            streetList.Add("CROSSINGTON");
            streetList.Add("CROWN VETCH");
            streetList.Add("CULLER");
            streetList.Add("CURIE");
            streetList.Add("CUTTY SARK");
            streetList.Add("CYPRESS");
            streetList.Add("DAPPLEFAWN");
            streetList.Add("DARVISH");
            streetList.Add("DASHING WAVE");
            streetList.Add("DAVENHAM");
            streetList.Add("DEERLAKE");
            streetList.Add("DEERWOODS");
            streetList.Add("DERBY CHASE");
            streetList.Add("DEVON DOWNS");
            streetList.Add("DEVON MILL");
            streetList.Add("DODD");
            streetList.Add("DOE");
            streetList.Add("DOECREEK");
            streetList.Add("DONEHOO");
            streetList.Add("DOUGLAS");
            streetList.Add("DRESDEN");
            streetList.Add("DUNHILL PLACE");
            streetList.Add("DUNHILL VIEW");
            streetList.Add("DUNHILL WAY");
            streetList.Add("EAGLES MERE");
            streetList.Add("EASTBOURNE");
            streetList.Add("EASTFIELD");
            streetList.Add("EASTSIDE");
            streetList.Add("EDISON");
            streetList.Add("ELITE");
            streetList.Add("ELK RIDGE");
            streetList.Add("ELLSBOROUGH");
            streetList.Add("ENGLISH OAK");
            streetList.Add("ESQUIRE");
            streetList.Add("EVENING PINE");
            streetList.Add("EXECUTIVE");
            streetList.Add("FALLEN LEAF");
            streetList.Add("FAWN");
            streetList.Add("FAWN LAKE");
            streetList.Add("FIELDSTONE");
            streetList.Add("FIELDSTONE EDGE");
            streetList.Add("FINDLEY");
            streetList.Add("FLYING SCOT");
            streetList.Add("FLYNN CROSSING");
            streetList.Add("FOX");
            streetList.Add("FOX CHASE");
            streetList.Add("FOXTHORNE");
            streetList.Add("FRIAR");
            streetList.Add("GANNETT NOOK");
            streetList.Add("GATE DANCER");
            streetList.Add("GLADEWOOD");
            streetList.Add("GLENEAGLES POINTE");
            streetList.Add("GLENMOOR");
            streetList.Add("GLENROSE");
            streetList.Add("GODDARD");
            streetList.Add("GOLDENROD");
            streetList.Add("GOLF CLUB");
            streetList.Add("GRAYSTONE");
            streetList.Add("GREATWOOD");
            streetList.Add("GRIMESBY");
            streetList.Add("GROMWELL");
            streetList.Add("GROVSNER");
            streetList.Add("HADDEN HALL");
            streetList.Add("HAMPTONS");
            streetList.Add("HAMPTONS CHASE");
            streetList.Add("HARBOUR");
            streetList.Add("HARBOUR COVE");
            streetList.Add("HARBOUR OVERLOOK");
            streetList.Add("HARBOUR RIDGE");
            streetList.Add("HASTINGS");
            streetList.Add("HATERLEIGH");
            streetList.Add("HAVENWOOD");
            streetList.Add("HAWKHORN");
            streetList.Add("HELLERI");
            streetList.Add("HENDRON");
            streetList.Add("HERMITAGE");
            streetList.Add("HIGHLAND GLEN");
            streetList.Add("HIGHMEADE");
            streetList.Add("HIGHOAKS");
            streetList.Add("HILLBROOKE");
            streetList.Add("HILLCREST");
            streetList.Add("HILLGATE");
            streetList.Add("HONOR");
            streetList.Add("HORADONG");
            streetList.Add("HUNTERS MOON");
            streetList.Add("HUNTINGTON");
            streetList.Add("HUNTINGTON DOWNS");
            streetList.Add("HUNTINGTON TRACE");
            streetList.Add("HUNTWICK");
            streetList.Add("HYDRANGEA");
            streetList.Add("INLET WOODS");
            streetList.Add("INTREPED CUT");
            streetList.Add("JEFFERSON");
            streetList.Add("JEFFERSON CREEK");
            streetList.Add("JOHNS VIEW");
            streetList.Add("JONES BRIDGE");
            streetList.Add("KEATON");
            streetList.Add("KENSINGTON");
            streetList.Add("KETTON");
            streetList.Add("KIMBALL BRIDGE");
            streetList.Add("KINGFIELD");
            streetList.Add("KRISTENSEN");
            streetList.Add("LAKE");
            streetList.Add("LAKE PINES POINTE");
            streetList.Add("LAKE SHORE");
            streetList.Add("LAKE SHORE OVERLOOK");
            streetList.Add("LAKE WINDWARD");
            streetList.Add("LAKE WINDWARD OVERLOOK");
            streetList.Add("LAKESIDE");
            streetList.Add("LAKEWAY");
            streetList.Add("LAKEWIND");
            streetList.Add("LAMBETS");
            streetList.Add("LANDINGS");
            streetList.Add("LANDINGS CHASE");
            streetList.Add("LANDINGS OVERLOOK");
            streetList.Add("LAUREL RIDGE");
            streetList.Add("LEAF");
            streetList.Add("LEAFWING");
            streetList.Add("LEATHERMAN");
            streetList.Add("LEEWARD RUN");
            streetList.Add("LEEWARD WALK");
            streetList.Add("LEGEND");
            streetList.Add("LEXINGTON WOODS");
            streetList.Add("LIGHTHOUSE POINTE");
            streetList.Add("LINKSIDE");
            streetList.Add("LINKSIDE OVERVIEW");
            streetList.Add("LITTLE CREEK");
            streetList.Add("LONGCREEK POINTE");
            streetList.Add("LONGPOINTE");
            streetList.Add("LUPINE");
            streetList.Add("MAGNOLIA");
            streetList.Add("MAGNOLIA BLOSSOM");
            streetList.Add("MAID MARION CLOSE");
            streetList.Add("MARCONI");
            streetList.Add("MARINERS");
            streetList.Add("MARKET");
            streetList.Add("MASTERS");
            streetList.Add("MAY APPLE");
            streetList.Add("MCFARLAND");
            streetList.Add("MCGINNIS FERRY");
            streetList.Add("MCGINNIS FERRY");
            streetList.Add("MCGINNIS VILLAGE");
            streetList.Add("MEADOW");
            streetList.Add("MEADOWRIDGE");
            streetList.Add("MEADOWS");
            streetList.Add("MEADOWS CREEK");
            streetList.Add("MELLBROOK");
            streetList.Add("MERIDIAN");
            streetList.Add("MILBURY");
            streetList.Add("MILLHAVEN");
            streetList.Add("MILLWICK");
            streetList.Add("MIRROWOOD");
            streetList.Add("MONTWOOD");
            streetList.Add("MORNING MIST");
            streetList.Add("MORNING PINE");
            streetList.Add("MORRIS");
            streetList.Add("MOSSY");
            streetList.Add("MOUNTAIN PINE");
            streetList.Add("MUIRFIELD");
            streetList.Add("MULBERRY MANOR");
            streetList.Add("NASSER");
            streetList.Add("NEWPORT");
            streetList.Add("NEWPORT BAY");
            streetList.Add("NEWPORT FAIRWAY");
            streetList.Add("NOBEL");
            streetList.Add("NORTHERDEN");
            streetList.Add("NOTTINGHAM");
            streetList.Add("OAK ARBOR");
            streetList.Add("OAK HOLLOW");
            streetList.Add("OAK RIDGE");
            streetList.Add("OAK TREE");
            streetList.Add("OAKLEIGH");
            streetList.Add("OAKVIEW");
            streetList.Add("OLD ALPHARETTA");
            streetList.Add("OLD MCGINNIS FERRY");
            streetList.Add("OLD MILTON");
            streetList.Add("OTTO LUYKEN");
            streetList.Add("OVERHILL");
            streetList.Add("OXBOROUGH");
            streetList.Add("OXFORD CLOSE");
            streetList.Add("OXFORD HALL");
            streetList.Add("OXFORDSHIRE");
            streetList.Add("PARK BRIDGE");
            streetList.Add("PARK CREEK");
            streetList.Add("PARK GLENN");
            streetList.Add("PARK WOODS");
            streetList.Add("PARKSIDE");
            streetList.Add("PARKVIEW");
            streetList.Add("PEACE CREEK");
            streetList.Add("PIN OAK");
            streetList.Add("PINION");
            streetList.Add("PLYMOUTH");
            streetList.Add("POINT");
            streetList.Add("PORTMARNOCK");
            streetList.Add("PORTRUSH");
            streetList.Add("PRESERVE");
            streetList.Add("PRESTON GLEN");
            streetList.Add("PRESTON RIDGE");
            streetList.Add("PRESTWICK");
            streetList.Add("PROSPECT");
            streetList.Add("QUAIL RUN");
            streetList.Add("QUEENSLAND");
            streetList.Add("RANGER");
            streetList.Add("RED JACKET");
            streetList.Add("RED MAPLE FOREST");
            streetList.Add("REDLEAF");
            streetList.Add("REDRIFT");
            streetList.Add("REINDEER");
            streetList.Add("RIDGE FIELD");
            streetList.Add("RIDGEFIELD");
            streetList.Add("RIDGEGATE");
            streetList.Add("RIDGEWOOD");
            streetList.Add("RISEN STAR");
            streetList.Add("ROBINS");
            streetList.Add("ROCKBERRY");
            streetList.Add("ROCKY BROOK");
            streetList.Add("ROSE MEADOW");
            streetList.Add("ROSE WALK");
            streetList.Add("ROSEWOOD");
            streetList.Add("ROXBURY");
            streetList.Add("SARGENT");
            streetList.Add("SAXONY");
            streetList.Add("SCHOONER");
            streetList.Add("SESSINGHAM");
            streetList.Add("SEVEN OAKS");
            streetList.Add("SEVEN SEAS");
            streetList.Add("SHADOW BROOK");
            streetList.Add("SHERINGHAM");
            streetList.Add("SHILOH");
            streetList.Add("SHIRLEY BRIDGE");
            streetList.Add("SIGNAL POINTE");
            streetList.Add("SILVERLEAF");
            streetList.Add("SMOKETREE");
            streetList.Add("SNOW CHIEF");
            streetList.Add("SNOWBERRY");
            streetList.Add("SORREL");
            streetList.Add("SOUTHLAKE");
            streetList.Add("SPIKE");
            streetList.Add("SPINNAKER");
            streetList.Add("SPRINGBERRY");
            streetList.Add("STAGHOUND");
            streetList.Add("STAMBRIDGE");
            streetList.Add("STATE BRIDGE");
            streetList.Add("STEVENS CREEK");
            streetList.Add("STONE CREEK");
            streetList.Add("STONEBURY");
            streetList.Add("STONEHAVEN");
            streetList.Add("STONEY BROOK");
            streetList.Add("SUMMER BREEZE");
            streetList.Add("SUMMERLIN");
            streetList.Add("SUMMERWOOD");
            streetList.Add("SUNBERRY");
            streetList.Add("SUNDEW");
            streetList.Add("SUNSET MAPLE");
            streetList.Add("SURREY RUN");
            streetList.Add("SWEET GUM FOREST");
            streetList.Add("SWEETBERRY");
            streetList.Add("TAHOE PINES");
            streetList.Add("TAMARACK");
            streetList.Add("TECHNOLOGY");
            streetList.Add("THERMOPYLAE");
            streetList.Add("THORNBURY");
            streetList.Add("TIDEWATER");
            streetList.Add("TIMBERCREEK");
            streetList.Add("TIMBERLINE");
            streetList.Add("TOMMY WALLACE");
            streetList.Add("TREE LAKE");
            streetList.Add("TREYFORD");
            streetList.Add("TROON");
            streetList.Add("TUMBLING CREEK");
            streetList.Add("TURNBERRY");
            streetList.Add("TWIN FLOWER");
            streetList.Add("ULSTER");
            streetList.Add("UNION HILL");
            streetList.Add("VALLEY BROOK");
            streetList.Add("VELVET");
            streetList.Add("VICARAGE");
            streetList.Add("VICTORIAN");
            streetList.Add("VINCA");
            streetList.Add("VINEBROOK");
            streetList.Add("VISTA FOREST");
            streetList.Add("WALNUT CREEK");
            streetList.Add("WATER LILLY");
            streetList.Add("WEATHERBORNE");
            streetList.Add("WEATHERLY");
            streetList.Add("WEBB BRIDGE");
            streetList.Add("WELBURY");
            streetList.Add("WELLINGBROUGH");
            streetList.Add("WELLSLEY");
            streetList.Add("WESSEX DOWNS");
            streetList.Add("WESTBURY");
            streetList.Add("WESTCHESTER");
            streetList.Add("WESTWIND");
            streetList.Add("WESTWIND POINTE");
            streetList.Add("WHITE OAK");
            streetList.Add("WHITE ROSE");
            streetList.Add("WHITESTONE");
            streetList.Add("WHITETAIL");
            streetList.Add("WILDWOOD");
            streetList.Add("WILLISTON");
            streetList.Add("WILLOW OAK");
            streetList.Add("WILLOW OVERLOOK");
            streetList.Add("WILLOW TREE");
            streetList.Add("WIND FLOWER");
            streetList.Add("WINDBROOKE");
            streetList.Add("WINDCREEK OVERLOOK");
            streetList.Add("WINDHAVEN");
            streetList.Add("WINDING OAK");
            streetList.Add("WINDLAND CLOSE");
            streetList.Add("WINDROSE");
            streetList.Add("WINDVIEW");
            streetList.Add("WINDWARD");
            streetList.Add("WINDWARD CONCOURSE");
            streetList.Add("WINDWARD CONCOURSE");
            streetList.Add("WINDWARD RIDGE");
            streetList.Add("WINWOOD");
            streetList.Add("WOOD ROSE");
            streetList.Add("WOODLAKE");
            streetList.Add("WOODRUN");
            streetList.Add("WOODS");
            streetList.Add("WOODVINE");
            streetList.Add("WYNGATE");
            streetList.Add("WYNRIDGE");
            streetList.Add("WYNRIDGE POINTE");
            streetList.Add("YEARLING CHASE");
            streetList.Add("YORKRIDGE");

            #endregion

        }

        public void Load()
        {
            try
            {
                //Create Database
                var di = new Widgetsphere.Autos.Install.DatabaseInstaller();
                var setup = new Widgetsphere.Autos.Install.InstallSetup();
                setup.InstallStatus = Widgetsphere.Autos.Install.InstallStatusConstants.Create;
                setup.MasterConnectionString = _masterConnection;
                setup.NewDatabaseName = _dbName;
                setup.ConnectionString = _connection;
                di.Install(setup);

                //Connect to new database
                //Widgetsphere.Autos.Business.ConfigurationValues.GetInstance().ConnectionString = _connection;

                //Create all data
                this.LoadMakeModels();
                this.LoadColors();
                this.LoadBodyTypes();
                this.LoadFuelTypes();
                this.LoadTransmissions();
                this.LoadFeatures();
                this.LoadUsers();
                this.LoadListings(_count);
                //this.LoadListingImages();
                //this.LoadBulletPoints();
                //this.LoadListingFeatures();

                LoadRepository(_connection);

                OnComplete(new EventArgs());
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private void LoadFeatures()
        {
            var itemList = new List<string>();

            #region Item list

            itemList.Add("AM/FM Radio");
            itemList.Add("Air Conditioning");
            itemList.Add("Alloy Wheels");
            itemList.Add("Anti-Lock Brakes");
            itemList.Add("Auto Headlight On/Off");
            itemList.Add("Beverage Holder (s)");
            itemList.Add("Bucket Seats");
            itemList.Add("CD Changer");
            itemList.Add("CD Player");
            itemList.Add("Center Arm Rest");
            itemList.Add("Child-Proof Locks");
            itemList.Add("Climate Control");
            itemList.Add("Convertible");
            itemList.Add("Cruise Control");
            itemList.Add("Digital Instrument Panel");
            itemList.Add("Driver's Side Air Bag");
            itemList.Add("Dual Climate Control");
            itemList.Add("Dual Exhaust");
            itemList.Add("Floor Mats");
            itemList.Add("Fog Lights");
            itemList.Add("Fold Down rear Seat");
            itemList.Add("Heated Mirrors");
            itemList.Add("Heated Seats");
            itemList.Add("High Performance Tires");
            itemList.Add("Interval Wipers");
            itemList.Add("Keyless Entry");
            itemList.Add("Leather Interior Trim");
            itemList.Add("Lumbar Support");
            itemList.Add("Map Light");
            itemList.Add("Memory Seat");
            itemList.Add("Navigation System");
            itemList.Add("Overhead Console");
            itemList.Add("Passenger Airbag");
            itemList.Add("Power Brakes");
            itemList.Add("Power Door Locks");
            itemList.Add("Power Drivers Seat");
            itemList.Add("Power Mirror");
            itemList.Add("Power Steering");
            itemList.Add("Power Windows");
            itemList.Add("Premium Sound System");
            itemList.Add("Rear Spoiler");
            itemList.Add("Rear Window Defroster");
            itemList.Add("Security Package");
            itemList.Add("Side Impact Air Bag");
            itemList.Add("Split Bench Seat");
            itemList.Add("Steering Wheel Audio Controls");
            itemList.Add("Sun Roof");
            itemList.Add("Tilt Steering Wheel");
            itemList.Add("Tinted Glass");
            itemList.Add("Traction Control");
            itemList.Add("Trip Computer");

            #endregion

            using (var context = new AutosEntities(_connection))
            {
                foreach (var s in itemList)
                {
                    context.AddItem(new Feature() { Name = s });
                }
                context.SaveChanges();
            }

        }

        private void LoadListingImages()
        {
            try
            {
                using (var context = new AutosEntities(_connection))
                {
                    List<Listing> listingCollection = null;
                    var count = -1;
                    var page = 1;
                    const int pageSize = 20000;

                    while ((count == -1) || ((page - 1) * pageSize) < count)
                    {
                        listingCollection = context.Listing
                                                   .OrderBy(x => x.ListingId)
                                                   .Skip((page - 1) * pageSize)
                                                   .Take(pageSize)
                                                   .ToList();

                        foreach (var listing in context.Listing.ToList())
                        {
                            var listingImageFile = listing.MakeModel.Make.Name + "_" + listing.MakeModel.Model.Name + ".jpg";
                            listingImageFile = listingImageFile.Replace(" ", string.Empty).ToLower();

                            //if (System.IO.File.Exists(System.IO.Path.Combine(@"C:\projects\work.net\Autos\Autos.Website\images", listingImageFile)))
                            //{
                            var listingImage = new ListingImage();
                            listingImage.FileName = listingImageFile;
                            listingImage.ListingId = listing.ListingId;
                            context.AddItem(listingImage);
                            //}

                            //Save and create a new one
                            //if (listingImageCollection.Count >= 1000)
                            {
                                context.SaveChanges();
                                //listingImageCollection = new ListingImageCollection();
                            }

                        }
                        //Increment Page
                        page++;
                    }

                    //Save trailers
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private void LoadBulletPoints()
        {
            using (var context = new AutosEntities(_connection))
            {
                List<Listing> listingCollection = null;
                var count = -1;
                var page = 1;
                const int pageSize = 10000;

                while ((count == -1) || ((page - 1) * pageSize) < count)
                {
                    listingCollection = context.Listing
                                               .OrderBy(x => x.ListingId)
                                               .Skip((page - 1) * pageSize)
                                               .Take(pageSize)
                                               .ToList();

                    foreach (var listing in listingCollection)
                    {
                        var itemCount = random.Next(0, 4);
                        for (var ii = 1; ii <= itemCount; ii++)
                        {
                            var bulletPoint = new BulletPoint();
                            bulletPoint.Text = "Bullet Point " + ii.ToString() + ", " + RandomString(10);
                            bulletPoint.ListingId = listing.ListingId;
                            context.AddItem(bulletPoint);
                        }

                        //Save and create a new one
                        //if (bulletPointCollection.Count >= 3000)
                        {
                            //context.SaveChanges();
                            //bulletPointCollection = new BulletPointCollection();
                        }

                    }
                    //Increment Page
                    page++;
                }

                //Save trailers
                context.SaveChanges();
            }
        }

        //private void LoadListingFeatures()
        //{
        //	try
        //	{
        //		using (var context = new AutosEntities(_connection))
        //		{
        //			var featureCollection = context.Feature.ToList();
        //			List<Listing> listingCollection = null;
        //			int count = -1;
        //			int page = 1;
        //			const int pageSize = 3000;

        //			while ((count == -1) || ((page - 1) * pageSize) < count)
        //			{
        //				listingCollection = context.Listing
        //					.OrderBy(x => x.ListingId)
        //					.Skip((page - 1) * pageSize)
        //				.Take(pageSize)
        //					.ToList();

        //				foreach (Listing listing in listingCollection)
        //				{
        //					//int numOfFeatures = random.Next((int)(featureCollection.Count * 0.2), (int)(featureCollection.Count * 0.98));
        //					//About 20% of time, create many fetures, other wise few
        //					int numOfFeatures = 0;
        //					if (random.Next(1, 5) == 1)
        //					{
        //						numOfFeatures = random.Next(6, 15);
        //					}
        //					else
        //					{
        //						numOfFeatures = random.Next(3, 6);
        //					}
        //					var featureIndexList = GetUniqueIndexes(numOfFeatures, featureCollection.Count);
        //					foreach (int index in featureIndexList)
        //					{
        //						if (listing.FeatureList.FirstOrDefault(x => x.FeatureId == featureCollection[index].FeatureId) == null)
        //						{
        //							listing.FeatureList.Add(featureIndexList[index]);
        //						}
        //					}

        //					//Save and creat a new one
        //					//if (listingFeatureCollection.Count >= 5000)
        //					//{
        //					//  listingFeatureCollection.Persist();
        //					//  listingFeatureCollection = new ListingFeatureCollection();
        //					//}

        //				}

        //				listingCollection.Persist();

        //				//Increment Page
        //				page++;
        //			}

        //			//Save trailers
        //			context.SaveChanges();
        //		}
        //	}
        //	catch (Exception ex)
        //	{
        //		throw;
        //	}
        //}

        private void LoadUsers()
        {
            try
            {
                using (var context = new AutosEntities(_connection))
                {
                    var metroCollection = context.Metro.ToList();
                    var makeCollection = context.Make.ToList();
                    var stateCollection = context.State.ToList();
                    var zipCollection = context.Zip.ToList();

                    var zipDocument = new XmlDocument();
                    var assembly = System.Reflection.Assembly.GetExecutingAssembly();
                    var stream = assembly.GetManifestResourceStream("TestData.Docs.zipcodes.xml");
                    var sr = new StreamReader(stream, System.Text.Encoding.UTF8);
                    zipDocument.LoadXml(sr.ReadToEnd());
                    sr.Close();

                    var userCount = context.UserAccount.Count();

                    //Create Dealers
                    int[] countArr = { 4, 2, 6, 4, 7, 3, 5, 7, 2, 8, 5 };
                    var index = 1;
                    foreach (var metro in metroCollection)
                    {
                        for (var ii = 0; ii < countArr[index % countArr.Length]; ii++)
                        {
                            var dealer = new Dealer();
                            context.AddItem(dealer);
                            dealer.Password = "test";
                            dealer.Email = "user" + (userCount + ii + 1) + "@test.com";
                            dealer.UserTypeId = (int)UserTypeConstants.Dealer;
                            dealer.FirstName = "John";
                            dealer.LastName = "Doe";

                            var cityName = cityList[random.Next(0, cityList.Count - 1)];

                            dealer.CompanyName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(nameList[random.Next(0, nameList.Count - 1)].ToLower()) + " " + makeCollection[random.Next(0, makeCollection.Count - 1)].Name + " of " + cityList[random.Next(0, cityList.Count - 1)];
                            dealer.MetroId = metro.MetroId;
                            dealer.Directions = "Take I-" + (random.Next(1, 10) * 10) + " East to " + cityName + " Highway exit, turn north on Highway " + random.Next(10, 150) + " (towards " + cityList[random.Next(0, cityList.Count - 1)] + "). Go approximately " + random.Next(2, 6) + " miles and turn right onto Montreal Road. " + cityList[random.Next(0, cityList.Count - 1)] + " Station is approximately " + random.Next(2, 6) + " miles on the left.";
                            dealer.Address1 = random.Next(100, 5000) + " " + streetList[random.Next(0, streetList.Count - 1)];
                            dealer.Address2 = "Suite " + random.Next(100, 500);
                            dealer.City = cityName;
                            dealer.OfficePhone = this.GetPhoneNumber();

                            XmlNodeList zipList = null;
                            XmlNode zipNode = null;
                            var stateName = string.Empty;
                            while (zipList == null || zipList.Count == 0)
                            {
                                stateName = stateCollection[random.Next(0, stateCollection.Count)].Abbr;
                                zipList = zipDocument.SelectNodes("statelist/state[@name='" + stateName + "']/ziplist/zip");
                                if (zipList.Count > 0)
                                {
                                    zipNode = zipList[random.Next(0, zipList.Count)];
                                    if (zipCollection.FirstOrDefault(x => x.Name == zipNode.Attributes["name"].Value) == null)
                                        zipList = null;
                                }
                            }

                            dealer.StateId = stateCollection.First(x => x.Abbr == stateName).StateId;
                            dealer.Latitude = double.Parse(zipNode.Attributes["latitude"].Value);
                            dealer.Longitude = double.Parse(zipNode.Attributes["longitude"].Value);
                            dealer.ZipId = zipCollection.First(x => x.Name == zipNode.Attributes["name"].Value).ZipId;
                            dealer.AlertFrequency = 0;

                            index++;
                        }
                    }

                    context.SaveChanges();
                    userCount = context.UserAccount.Count();

                    //Create Individuals
                    for (var ii = 1; ii <= USER_COUNT; ii++)
                    {
                        var userAccount = new UserAccount();
                        userAccount.Active = true;
                        userAccount.Password = "test";
                        userAccount.Email = "user" + (userCount + ii) + "@test.com";
                        userAccount.UserTypeId = (int)UserTypeConstants.Individual;

                        var cityName = cityList[random.Next(0, cityList.Count - 1)];

                        userAccount.Address1 = random.Next(100, 5000) + " " + streetList[random.Next(0, streetList.Count - 1)];
                        userAccount.Address2 = "Suite " + random.Next(100, 500);
                        userAccount.City = cityName;
                        userAccount.OfficePhone = this.GetPhoneNumber();
                        userAccount.FirstName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(nameList[random.Next(0, nameList.Count - 1)].ToLower()) + " " + makeCollection[random.Next(0, makeCollection.Count - 1)].Name + " of " + cityList[random.Next(0, cityList.Count - 1)];
                        userAccount.LastName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(nameList[random.Next(0, nameList.Count - 1)].ToLower()) + " " + makeCollection[random.Next(0, makeCollection.Count - 1)].Name + " of " + cityList[random.Next(0, cityList.Count - 1)];

                        XmlNodeList zipList = null;
                        XmlNode zipNode = null;
                        var stateName = string.Empty;
                        while (zipList == null || zipList.Count == 0)
                        {
                            stateName = stateCollection[random.Next(0, stateCollection.Count)].Abbr;
                            zipList = zipDocument.SelectNodes("statelist/state[@name='" + stateName + "']/ziplist/zip");
                            if (zipList.Count > 0)
                            {
                                zipNode = zipList[random.Next(0, zipList.Count)];
                                if (zipCollection.FirstOrDefault(x => x.Name == zipNode.Attributes["name"].Value) == null)
                                    zipList = null;
                            }
                        }

                        userAccount.StateId = stateCollection.FirstOrDefault(x => x.Abbr == stateName).StateId;
                        try
                        {
                            userAccount.Latitude = double.Parse(zipNode.Attributes["latitude"].Value);
                            userAccount.Longitude = double.Parse(zipNode.Attributes["longitude"].Value);
                            userAccount.ZipId = zipCollection.FirstOrDefault(x => x.Name == zipNode.Attributes["name"].Value).ZipId;
                        }
                        catch (Exception ex)
                        {
                            userAccount.Latitude = null;
                            userAccount.Longitude = null;
                            userAccount.ZipId = null;
                        }
                        userAccount.AlertFrequency = 0;

                        context.AddItem(userAccount);

                        if (ii % 100 == 0)
                        {
                            context.SaveChanges();
                            //userAccountCollection = new UserAccountCollection();
                            System.Diagnostics.Debug.WriteLine("User: " + index);
                        }

                    }
                    System.Diagnostics.Debug.WriteLine("User Complete");

                    //Save all users
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private void LoadTransmissions()
        {
            try
            {
                using (var context = new AutosEntities(_connection))
                {
                    context.AddItem(new Transmission() { Name = "Automatic" });
                    context.AddItem(new Transmission() { Name = "Manual" });
                    context.AddItem(new Transmission() { Name = "Automanual" });
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private void LoadFuelTypes()
        {
            try
            {
                using (var context = new AutosEntities(_connection))
                {
                    context.AddItem(new FuelType() { Name = "Biodiesel" });
                    context.AddItem(new FuelType() { Name = "CNG" });
                    context.AddItem(new FuelType() { Name = "Diesel" });
                    context.AddItem(new FuelType() { Name = "Electric" });
                    context.AddItem(new FuelType() { Name = "Ethanol - FFV" });
                    context.AddItem(new FuelType() { Name = "Gasoline" });
                    context.AddItem(new FuelType() { Name = "Hybrid-Electric" });
                    context.AddItem(new FuelType() { Name = "Steam" });
                    context.AddItem(new FuelType() { Name = "Other" });
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private void LoadColors()
        {
            try
            {
                using (var context = new AutosEntities(_connection))
                {
                    //Load the Colors
                    context.AddItem(new Color { Name = "White" });
                    context.AddItem(new Color { Name = "Green" });
                    context.AddItem(new Color { Name = "Blue" });
                    context.AddItem(new Color { Name = "Red" });
                    context.AddItem(new Color { Name = "Gray" });
                    context.AddItem(new Color { Name = "Black" });
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        private void LoadBodyTypes()
        {
            try
            {
                using (var context = new AutosEntities(_connection))
                {
                    //Load the Colors
                    context.AddItem(new BodyType() { Name = "Sedan" });
                    context.AddItem(new BodyType() { Name = "Coupe" });
                    context.AddItem(new BodyType() { Name = "Convertible" });
                    context.AddItem(new BodyType() { Name = "Hatchback/Wagon" });
                    context.AddItem(new BodyType() { Name = "Pickup Truck" });
                    context.AddItem(new BodyType() { Name = "Sport Utility" });
                    context.AddItem(new BodyType() { Name = "Van/Minivan" });
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        private void LoadMakeModels()
        {
            try
            {
                using (var context = new AutosEntities(_connection))
                {
                    var document = new XmlDocument();
                    var assembly = System.Reflection.Assembly.GetExecutingAssembly();

                    var stream = assembly.GetManifestResourceStream("TestData.Docs.autos.xml");
                    var sr = new StreamReader(stream, System.Text.Encoding.UTF8);
                    document.LoadXml(sr.ReadToEnd());
                    sr.Close();

                    //****************************************************
                    //Load the makes
                    foreach (XmlNode node in document.DocumentElement.ChildNodes)
                    {
                        var make = new Make() { Name = node.Attributes["name"].Value };
                        context.AddItem(make);

                        //Load the models
                        foreach (XmlNode node2 in node.ChildNodes)
                        {
                            var model = new Model();
                            model.Name = node2.Attributes["name"].Value;
                            model.MpgCity = 15 + (random.Next() % 25);
                            model.MpgHighway = model.MpgCity + 5;
                            context.AddItem(model);

                            context.AddItem(new MakeModel() { Make = make, Model = model });
                        }

                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private void LoadListings(int count)
        {
            const int ItemsPerBlock = 100;
            var blocks = (count / ItemsPerBlock) + ((count % ItemsPerBlock) == 0 ? 0 : 1);
            for (var ii = 1; ii <= blocks; ii++)
            {
                LoadListingsBlock(ItemsPerBlock);
            }
        }

        private void LoadListingsBlock(int itemCount)
        {
            try
            {
                using (var context = new AutosEntities(_connection)) 
                {
                    var stateCollection = context.State.ToList();
                    var metroCollection = context.Metro.ToList();
                    var colorCollection = context.Color.ToList();
                    var makeModelCollection = context.MakeModel.ToList();
                    var makeCollection = context.Make.ToList();
                    var modelCollection = context.Model.ToList();
                    var dealerCollection = context.Dealer.ToList();
                    var transmissionCollection = context.Transmission.ToList();
                    var fuelTypeCollection = context.FuelType.ToList();
                    var userAccountCollection = context.UserAccount.Where(x => x.UserTypeId == (int)UserTypeConstants.Individual).ToList();
                    var bodyTypeCollection = context.BodyType.ToList();

                    for (var ii = 1; ii <= itemCount; ii++) 
                    {
                        var listing = new Listing();
                        listing.Active = true;
                        listing.ColorExtId = colorCollection[(random.Next() % colorCollection.Count)].ColorId;
                        listing.ColorIntId = colorCollection[(random.Next() % colorCollection.Count)].ColorId;
                        listing.TransmissionId = transmissionCollection[(random.Next() % transmissionCollection.Count)].TransmissionId;

                        var makeModel = makeModelCollection[(random.Next() % makeModelCollection.Count)];
                        listing.MakeModelId = makeModel.MakeModelId;

                        //33% have Dealers
                        //XmlNode zipNode = null;
                        //string stateName = string.Empty;
                        if ((random.Next() % 3) == 0)
                        {
                            var dealer = dealerCollection[(random.Next(0, dealerCollection.Count))];
                            listing.UserId = dealer.UserId;
                            listing.MetroId = dealer.MetroId;
                        }
                        else
                        {
                            listing.UserId = userAccountCollection[(random.Next(0, userAccountCollection.Count))].UserId;
                        }

                        listing.ExpirationDate = DateTime.Now.AddDays(30);
                        listing.Description = GetNextFreeText();
                        listing.Year = random.Next(1980, DateTime.Now.Year + 1);
                        listing.Price = 10000 + (random.Next(0, 30000));
                        listing.Price -= (listing.Price % 100);
                        listing.Invoice = listing.Price - 1000;
                        listing.Mileage = 5000 + (random.Next(0, 95000));
                        listing.IsFeatured = (random.Next(1, 30) == 1);
                        listing.ListDate = DateTime.Now.AddDays(-random.Next(0, 1095));
                        listing.SetValue(Listing.FieldNameConstants.Title, this.GetTitle(), true);

                        //Make 80% Gas
                        if ((random.Next() % 5) < 4)
                            listing.FuelTypeId = fuelTypeCollection[5].FuelTypeId; //Gasoline
                        else //Split 20% between others
                            listing.FuelTypeId = fuelTypeCollection[(random.Next() % fuelTypeCollection.Count)].FuelTypeId;

                        //BodyType
                        listing.BodyTypeId = bodyTypeCollection[(random.Next() % bodyTypeCollection.Count)].BodyTypeId;

                        //Cylinders
                        switch (random.Next() % 10)
                        {
                            case 0:
                            case 1:
                                listing.Cylinders = 4;
                                break;
                            case 2:
                            case 3:
                            case 4:
                            case 5:
                            case 6:
                                listing.Cylinders = 6;
                                break;
                            case 7:
                            case 8:
                            case 9:
                                listing.Cylinders = 8;
                                break;
                        }

                        //if(System.IO.File.Exists(System.IO.Path.Combine(@"C:\projects\work.net\Autos\Autos.Website\images", listingImageFile)))
                        //  listing.ListingImages = listingImageFile;

                        var liter = 3 + (random.Next() % 3);
                        var valve = (random.Next() % 2);
                        var hp = 250 + (random.Next() % 100);
                        listing.Engine = liter + ".0L V" + listing.Cylinders + " " + hp + "HP";
                        listing.Vin = this.RandomString(17);
                        //Stock Number [1,000,000..60,000,000]
                        listing.StockNumber = (1000000 + (random.Next() % 50000000)).ToString();

                        //Make 80% new cars
                        if ((random.Next() % 5) < 4)
                            listing.ConditionId = 1;
                        else //Split 20% between used/certified
                            listing.ConditionId = (((random.Next() % 3) == 0) ? 3 : 1);

                        //Trim: 33%=SX, 66%=LX
                        listing.TrimLevel = (((random.Next() % 2) == 0) ? "SX" : "LX");
                        context.AddItem(listing);
                    }
                    context.SaveChanges();

                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        private string RandomString(int length)
        {
            try
            {
                if (length < 1)
                    length = 1;

                var retval = string.Empty;
                for (var ii = 0; ii < length; ii++)
                {
                    //Alpha/Numeric 50/50
                    if ((random.Next() % 2) == 0)
                        retval += (char)(65 + (random.Next() % 26));
                    else
                        retval += (char)(48 + (random.Next() % 10));
                }
                return retval;

            }
            catch (Exception ex)
            {
                throw;
            }

        }

        private List<int> GetUniqueIndexes(int count, int maxIndex)
        {
            if (count > maxIndex)
            {
                throw new Exception("Count can not be greater than MaxIndex!");
            }

            var retval = new List<int>();

            while (retval.Count < count)
            {
                var testValue = random.Next(maxIndex);
                if (!retval.Contains(testValue))
                    retval.Add(testValue);
            }

            return retval;
        }

        private string GetPhoneNumber()
        {
            var retval = string.Empty;
            for (var ii = 0; ii < 10; ii++)
            {
                retval += random.Next(0, 9).ToString();
                if ((ii == 2) || (ii == 5))
                    retval += "-";
            }
            return retval;
        }

        private int titleIndex = 0;

        private string GetTitle()
        {
            string[] s =
                {
                    "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
                    "Cras malesuada vestibulum dui. In facilisis. ",
                    "Morbi justo sem, varius a, porttitor a, eleifend vitae, justo. ",
                    "Ut posuere. Nulla facilisis auctor erat. ",
                    "Fusce vel ante id risus sagittis aliquam. ",
                    "Integer tempus dui et quam. Ut tincidunt. ",
                    "Sed mauris arcu, vehicula in, tincidunt nec, aliquet non, augue. ",
                    "Integer lacinia. Quisque enim metus, posuere ac, faucibus a, dignissim ut, ligula. ",
                    "Phasellus aliquet ultrices purus. ",
                    "Integer magna nulla, sollicitudin nonummy, dignissim vitae, vulputate in, elit. ",
                    "Quisque velit. ",
                    "Donec est tellus, feugiat non, adipiscing eget, adipiscing at, ipsum. ",
                    "Nulla tristique molestie felis. ",
                    "Integer neque mi, gravida in, elementum id, hendrerit eget, metus.",
                    "Sed at sem.",
                    "Suspendisse vestibulum. ",
                    "Praesent dolor metus, eleifend vel, convallis fringilla, viverra laoreet, mauris.",
                    "Maecenas elementum.",
                    "Maecenas cursus. ",
                    "Fusce at odio.", "Duis a mi non diam tincidunt congue.",
                    "Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos.",
                    "Proin condimentum dignissim nisl.", "Fusce at lorem.", "Phasellus sed lacus euismod ipsum scelerisque nonummy.",
                    "Sed eu nibh.",
                    "Nulla pretium scelerisque erat.", "Suspendisse gravida ornare ante.", "Praesent eu felis vel justo facilisis rutrum.",
                    "Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.", "Fusce bibendum.",
                    "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
                    "Vivamus odio ante, facilisis eget, ullamcorper id, tincidunt ac, quam.",
                    "Cras et enim.", "Praesent hendrerit dolor sit amet ligula.",
                    "Vestibulum urna sapien, consequat eget, luctus eu, euismod eu, sem.",
                    "Donec ornare.", "Vivamus vulputate sem in erat.", "Suspendisse turpis.",
                    "Donec ut orci vel nulla egestas venenatis.", "Aenean nec arcu ac lorem semper tempor.", "In volutpat."
                    , "Ut pharetra sollicitudin purus.", "Nulla facilisi.", "Aenean arcu neque, vehicula non, placerat ac, tempor eget, odio.", "Vestibulum posuere.", "Aenean vel pede.", "Integer et velit.", "Donec congue odio nec sapien.", "Nulla dolor tellus, pretium quis, pulvinar porta, tristique sit amet, tellus.", "Sed orci lacus, suscipit eu, rutrum nec, varius non, erat.", "Quisque accumsan, ipsum eget consectetuer consequat, elit dui consequat tellus, eu placerat tortor odio ac ligula.", "Aenean mollis.", "Vestibulum nunc.", "Aenean egestas lacinia massa.", "Donec vehicula, purus quis cursus convallis, lacus eros egestas mauris, a porttitor mauris risus quis elit.", "Praesent libero.", "Integer orci.", "Nulla nec ante.", "Praesent aliquet est sed erat scelerisque euismod.", "Curabitur euismod quam sed est.", "Vivamus quis mi.", "Nunc id quam ac ipsum iaculis vestibulum.", "Etiam quis orci.", "Donec tincidunt posuere erat.", "Maecenas justo elit, mattis et, nonummy ac, ultrices et, lectus.", "Donec sed arcu eu quam sodales ornare.", "Aenean ultricies lorem sed turpis.", "Quisque nonummy tortor quis neque.", "Nam ut sem non nisi mollis blandit.", "Nullam eget augue.", "Vestibulum adipiscing rhoncus nisl.", "Proin et orci vel urna fringilla rutrum.", "Vivamus arcu elit, luctus id, scelerisque quis, eleifend eget, magna.", "Proin varius tempus pede.", "Suspendisse augue quam, mollis id, convallis in, molestie nec, nibh.", "Donec a nunc.", "Morbi egestas consectetuer neque.", "Nullam molestie neque in lectus.", "Quisque nonummy magna interdum libero.", "Donec ac augue."
                };

            if (titleIndex >= s.Length)
                titleIndex = 0;

            return s[titleIndex++];
        }

        private StreamReader freeTextReader = null;

        private string GetNextFreeText()
        {
            if (freeTextReader == null)
            {
                var assembly = System.Reflection.Assembly.GetExecutingAssembly();
                var stream = assembly.GetManifestResourceStream(@"TestData.Data.wrnpc11.txt");
                freeTextReader = new StreamReader(stream, System.Text.Encoding.UTF8);
            }

            var text = string.Empty;
            while ((text == string.Empty) && (!freeTextReader.EndOfStream))
            {
                text = freeTextReader.ReadLine();
                if (text.Length > 1000)
                {
                    text = text.Substring(0, 997) + "...";
                }
            }

            if (freeTextReader.EndOfStream)
            {
                freeTextReader.Close();
                freeTextReader = null;
                text = GetNextFreeText();
            }

            return text;

        }

        public static bool CeleriqRunning()
        {
            try
            {
                using (var serverFactory = SystemCoreInteractDomain.GetCoreFactory(ConfigHelper.DatastoreServer, ConfigHelper.DatastorePort))
                {
                    var core = serverFactory.CreateChannel();
                    var q = core.GetPublicKey();
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public static void LoadRepository(string connectionString)
        {
            Console.WriteLine("WCFKey: " + RepositoryHelper.REPOSITORYID);

            var credentials = new UserCredentials();
            using (var factory = SystemCoreInteractDomain.GetCoreFactory(ConfigHelper.DatastoreServer, ConfigHelper.DatastorePort))
            {
                var server = factory.CreateChannel();
                credentials.UserName = "root";
                credentials.Password = "password";
                credentials.Password = SecurityHelper.Encrypt(server.GetPublicKey(), credentials.Password);
            }

            #region Check if repository exists

            using (var serverFactory = SystemCoreInteractDomain.GetCoreFactory(ConfigHelper.DatastoreServer, ConfigHelper.DatastorePort))
            {
                var server = serverFactory.CreateChannel();

                if (server.RepositoryExists(new Guid(RepositoryHelper.REPOSITORYID), credentials))
                {
                    var item = new RepositorySchema();
                    item.LoadXml(GetRepositoryTemplate());
                    item.ID = new Guid(RepositoryHelper.REPOSITORYID);
                    item.Name = "Autos";
                    server.DeleteRepository(item, credentials);
                }

                if (!server.RepositoryExists(new Guid(RepositoryHelper.REPOSITORYID), credentials))
                {
                    #region Create repository if not exists
                    var item = new RepositorySchema();
                    item.LoadXml(GetRepositoryTemplate());
                    item.ID = new Guid(RepositoryHelper.REPOSITORYID);
                    item.Name = "Autos";
                    server.SaveRepository(item, credentials);
                    #endregion
                }
            }

            #endregion

            using (var factory = RepositoryConnection.GetFactory(ConfigHelper.DatastoreServer, ConfigHelper.DatastorePort))
            {
                var service = factory.CreateChannel();
                service.Clear(new Guid(RepositoryHelper.REPOSITORYID), credentials);
                var connection = new RepositoryConnection(new Guid(RepositoryHelper.REPOSITORYID));
                var schema = connection.GetSchema(credentials, service);

                var maxID = 0;
                const int BLOCK = 1000;
                var count = 0;
                using (var context = new AutosEntities(connectionString))
                {
                    var list = context.Listing
                                      .Where(x => x.Active)
                                      .OrderBy(x => x.ListingId)
                                      .Take(BLOCK)
                                      .ToList();

                    while (list.Count > 0)
                    {
                        maxID = list.Max(x => x.ListingId);

                        var indexedList = new List<ListingItem>();
                        foreach (var job in list)
                        {
                            indexedList.Add(job.ToIndexedItem());
                            if (indexedList.Count % 50 == 0)
                            {
                                connection.UpdateData(schema, indexedList, credentials, service);
                                count += indexedList.Count;
                                indexedList = new List<ListingItem>();
                                Console.WriteLine("Processed: " + count.ToString("###,###,##0"));
                            }
                        }

                        if (indexedList.Count > 0)
                            connection.UpdateData(schema, indexedList, credentials, service);

                        list = context.Listing
                                      .Where(x => x.Active && x.ListingId > maxID)
                                      .OrderBy(x => x.ListingId)
                                      .Take(BLOCK)
                                      .ToList();

                    }

                }
            }
        }

        private static string GetRepositoryTemplate()
        {
            var a = Assembly.GetExecutingAssembly();
            var st = a.GetManifestResourceStream("TestData.AutoItem.hpds");
            var sr = new StreamReader(st);
            return sr.ReadToEnd();
        }

    }

}